package shop.controller;

import common.model.result.Result;
import common.model.shop.Shop;

import javax.websocket.server.PathParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import shop.service.IShopService;


@RestController
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    private IShopService shopService;
    //前台部分
    /**
     * 查询商铺详情
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    public Result detail(@PathVariable Long id) {
        // 查询商铺详情
        return shopService.findById(id);
    }
    /**
     * 获取当前商品的商品卡片
     * @param id
     * @return
     */
    @GetMapping("/card")
    public Result shopCard(@PathParam(value = "shpoId") Long id) {
        System.out.println(id);
        // 查询商铺详情
        return shopService.getShopCard(id);
    }

    //查询当前登录用户是否有商铺
    @GetMapping("/hasShop")
    public Result hasShop(@RequestHeader(value = "uid") Long uid) {
        return shopService.hasShop(uid);
    }

    //后台部分
    /**
     * 查询商铺列表
     * @param
     * @return
     */
    @GetMapping("/jiang/list")
    public Result list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) {
        return shopService.getShopList(page, size);
    }
    /**
     * 新增商铺
     * @param shop
     * @return
     */
    @PostMapping("/jiang/add")
    public Result addShop(@RequestBody Shop shop) {
        return shopService.addShop(shop);
    }
    /**
     * 修改商铺
     * @param shop
     * @return
     */
    @PostMapping("/jiang/update")
    public Result updateShop(@RequestBody Shop shop) {
        return shopService.updateShop(shop);
    }
    /**
     * 删除商铺
     * @param id
     * @return
     */
    @PostMapping("/jiang/delete/{id}")
    public Result deleteShop(@RequestParam Long id) {
        return shopService.deleteShop(id);
    }

}
